package com.py.credit.entity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

public class GuijiEntity implements  Comparable<GuijiEntity>{
	private String name;
	private String messgae;
	private String time;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getMessgae() {
		return messgae;
	}
	public void setMessgae(String messgae) {
		this.messgae = messgae;
	}
	public String getTime() {
		return time;
	}
	public void setTime(String time) {
		this.time = time;
	}
	
	@Override
	public int compareTo(GuijiEntity g) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try { 
		Date dt1 = format.parse(this.getTime());  
		Date dt2 = format.parse(g.getTime()); 
		
		if(dt1.getTime() >= dt2.getTime()){
			return -1;
		}else{
			return 1;
		}
		} catch (Exception e) {  
			 e.printStackTrace();  
		}  
		return 0;  
	}
	
	public static void main(String[] args) {  
        List<GuijiEntity> list = new ArrayList<GuijiEntity>();  
        
        GuijiEntity GuijiEntity1 = new GuijiEntity();
        GuijiEntity1.setName("1");
        GuijiEntity1.setTime("2018-07-03 10:47:26");
        
        GuijiEntity GuijiEntity2 = new GuijiEntity();
        GuijiEntity2.setName("2");
        GuijiEntity2.setTime("2018-07-05 10:47:26");
        
        GuijiEntity GuijiEntity3 = new GuijiEntity();
        GuijiEntity3.setName("3");
        GuijiEntity3.setTime("2018-07-05 11:47:26");
        list.add(GuijiEntity1);
        list.add(GuijiEntity2);
        list.add(GuijiEntity3);
        list.forEach(s -> {System.out.println(s.getName()+" "+s.getTime());});
        Collections.sort(list);  
         
        list.forEach(s -> {System.out.println(s.getName()+" "+s.getTime());});
   } 

}
